package resteasytest;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.Response;

@Path("/message")
public class MessageRestService {
	public MessageRestService(){}
	@GET 
    @Path("/printMessage/{param}")  
	public Response printMessage(@PathParam("param") String msg, @MatrixParam("color") String color){
		String result = String.format("Restful example: %s with color %s... ahahaha v3", msg, color);
		return Response.status(200).entity(result).build();
	}
	
	@GET
	@Path("/getMessage/{id}")
	@Produces("application/json") 
	public Response getMessage(@PathParam("id") int id){
		Message msg = new Message();
		msg.setId(id);
		msg.setContent("Haha first message...");
//		return msg;
		return Response.status(200).entity(msg).build();
	}
	
	@GET
	@Path("/getMessageList")
	@Produces("applicaitno/json")
	public List<Integer> getMessageList(){
		List<Integer> messageList = new ArrayList<Integer>();
		for (int i=0; i < 10; i++){
			Message msg = new Message();
			msg.setId(i);
			msg.setContent(String.format("This is the %d message...", i));
			messageList.add(i);
		}
//		GenericEntity<List<Message>> entity = new GenericEntity<List<Message>>(messageList) {};
//		Object[] messageArray =  messageList.toArray();
//		return Response.status(200).entity(messageList).build();
		return messageList;
	}
//	public Response getBooks(){
//		
//	}
}
